from .conn_mysql import ConnectMysql

import pymysql

class ConsumPtion:

    def __init__(self):
        super().__init__()

    def get_return(self, company_id=None, consumption_id=None):

        conn_obj = ConnectMysql()

        if not all((company_id, consumption_id)):

            return {
                'status': -1,
                'errorCode': 1,
                'errorMsg':f'请检查参数是否合法,company_id:{company_id},consumption_id:{consumption_id}',
                'resultBody':None
            }
        
        else:

            all_sql = 'select * from consumption where company_id = %s and consumption_id = %s'

            consumption_info = conn_obj.select_one(all_sql, (company_id,consumption_id))

            if bool(consumption_info) is False:
    
                conn_obj.close()

                return {
                    'status': -1,
                    'errorCode': 2,
                    'errorMsg':f'请检查该company_id是否有对该consumption_id的关注行为,company_id:{company_id},consumption_id:{consumption_id}',
                    'resultBody':None
                }

            else:

                consumption_info_id = consumption_info['consumption_id']

                company_sql = 'select * from company where id = %s'

                company_info = conn_obj.select_one(company_sql, (consumption_info_id))

                if bool(company_info) is False:
    
                    conn_obj.close()

                    return {
                        'status': -1,
                        'errorCode': 4,
                        'errorMsg':f'请检查该company是否还存在,consumption_id:{consumption_id}',
                        'resultBody':None
                    }

                conn_obj.close()

                return {
                    'status': 1,
                    'errorCode': None,
                    'errorMsg':None,
                    'resultBody':{'consumption_company':company_info}
                }
